import Vue from 'vue'
// eslint-disable-next-line import/no-duplicates
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'

// 解决Uncaught (in promise) Error: Redirected when going from xx to xx
// eslint-disable-next-line import/no-duplicates
import Router from 'vue-router'
const originalPush = Router.prototype.push
Router.prototype.push = function push(location, onResolve, onReject) {
  if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
  return originalPush.call(this, location).catch(err => err)
}

Vue.use(VueRouter)
var defaultToutes = {
  '/': {
    path: '/',
    name: 'home',
    // TODO remove
    // redirect: '/test',
    component: Home
  },
  '/main': {
    path: '/main',
    name: 'main',
    component: () => import('../views/Main.vue')
  },

  '/contactlist': {
    path: '/contactlist',
    name: 'contact/list',
    component: () => import('../views/project/contact/list.vue')
  },
  '/homepage': {
    path: '/homepage',
    name: 'homepage',
    component: () => import('../views/HomePage.vue')
  },
  '/list': {
    path: '/list',
    name: 'list',
    component: () => import('../views/List.vue')
  },

  '/flowlist': {
    path: '/flowlist',
    name: 'flowlist',
    component: () => import('../views/flow/Flowlist.vue')
  },
  '/reportlist': {
    path: '/reportlist',
    name: 'reportlist',
    component: () => import('../views/report/Reportlist.vue')
  },
  '/reportresult': {
    path: '/reportresult',
    name: 'reportresult',
    component: () => import('../views/report/Reportresult.vue')
  },
  '/sdlist': {
    path: '/sdlist',
    name: 'sdlist',
    component: () => import('../components/Sdlist.vue')
  },
  '/sdlistsub': {
    path: '/sdlistsub',
    name: 'sdlistsub',
    component: () => import('../components/Sdlistsub.vue')
  },
  '/card': {
    path: '/card',
    name: 'card',
    component: () => import('../views/Card.vue')
  },
  '/action': {
    path: '/action',
    name: 'action',
    component: () => import('../views/scenario/Action.vue')
  },
  '/newtag': {
    path: '/newtag',
    name: 'newtag',
    component: () => import('../views/NewTag.vue')
  },
  '/showcomplete': {
    path: '/showcomplete',
    name: 'showcomplete',
    component: () => import('../views/ShowComplete.vue')
  },
  '/showrank': {
    path: '/showrank',
    name: 'showrank',
    component: () => import('../views/ShowRank.vue')
  },
  '/mine': {
    path: '/mine',
    name: 'mine',
    component: () => import('../views/Mine.vue')
  },
  '/idownerMulti': {
    path: '/idownerMulti',
    name: 'idownerMulti',
    component: () => import('../components/IdownerMulti.vue')
  },
  '/idownerMultiForFilter': {
    path: '/idownerMultiForFilter',
    name: 'idownerMultiForFilter',
    component: () => import('../components/IdownerMultiForFilter.vue')
  },
  '/flowcard': {
    path: '/flowcard',
    name: 'flowcard',
    component: () => import('../views/flow/Flowcard.vue')
  },
  '/about': {
    path: '/about',
    name: 'about',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
  },
  '/new': {
    path: '/new',
    name: 'new',
    component: () => import('../views/New.vue')
  },
  '/edit': {
    path: '/edit',
    name: 'edit',
    component: () => import('../views/Edit.vue')
  },
  '/ref': {
    path: '/ref',
    name: 'ref',
    component: () => import('../components/Ref.vue')
  },
  '/orgRef': {
    path: '/orgRef',
    name: 'orgRef',
    component: () => import('../components/orgRef.vue')
  },
  '/refaccount3': {
    path: '/refaccount3',
    name: 'refaccount3',
    component: () => import('../components/RefAccount3.vue')
  },
  '/map': {
    path: '/map',
    name: 'map',
    component: () => import('../components/Map.vue')
  },
  '/map4common': {
    path: '/map4common',
    name: 'map4common',
    component: () => import('../components/MapForCommon.vue')
  },
  '/mappath': {
    path: '/mappath',
    name: 'mappath',
    component: () => import('../components/MapPath.vue')
  },
  '/refmulti': {
    path: '/refmulti',
    name: 'refmulti',
    component: () => import('../components/Refmulti.vue')
  },
  '/refmulti4account': {
    path: '/refmulti4account',
    name: 'refmulti4account',
    component: () => import('../components/Refmulti4Account.vue')
  },
  '/relnew': {
    path: '/relnew',
    name: 'relnew',
    component: () => import('../components/RelNew.vue')
  },
  '/sdnew': {
    path: '/sdnew',
    name: 'sdnew',
    component: () => import('../views/Sdnew.vue')
  },
  '/hzxydlproduct': {
    path: '/hzxydlproduct',
    name: 'hzxydlproduct',
    component: () => import('../views/HzxydlProduct.vue')
  },
  '/changpwd': {
    path: '/changpwd',
    name: 'changpwd',
    component: () => import('../components/Changpwd.vue')
  },
  '/forgetpwd': {
    path: '/forgetpwd',
    name: 'forgetpwd',
    component: () => import('../components/Forgetpwd.vue')
  },
  '/modifyInfo': {
    path: '/modifyInfo',
    name: 'modifyInfo',
    component: () => import('../components/modifyInfo.vue')
  },
  '/activitynew': {
    path: '/activitynew',
    name: 'activitynew',
    component: () => import('../views/ActivityNew.vue')
  },
  '/qiandaonew': {
    path: '/qiandaonew',
    name: 'qiandaonew',
    component: () => import('../views/QiandaoNew.vue')
  },
  '/activityedit': {
    path: '/activityedit',
    name: 'activityedit',
    component: () => import('../views/ActivityEdit.vue')
  },
  '/activitybfjl': {
    path: '/activitybfjl',
    name: 'activitybfjl',
    component: () => import('../views/ActivityBfjl.vue')
  },
  '/activityqian': {
    path: '/activityqian',
    name: 'activityqian',
    component: () => import('../views/activity/ActivityQian.vue')
  },
  '/bizcalendar': {
    path: '/bizcalendar',
    name: 'bizcalendar',
    component: () => import('../views/bizcalendar.vue')
  },
  '/billupload': {
    path: '/billupload',
    name: 'billupload',
    component: () => import('../components/Billupload.vue')
  },
  '/renew': {
    path: '/renew',
    name: 'renew',
    component: () => import('../views/Copy.vue')
  },
  '/newversion': {
    path: '/newversion',
    name: 'newversion',
    component: () => import('../views/Copy.vue')
  },
  '/campaignhyysbx': {
    path: '/campaignhyysbx',
    name: 'campaignhyysbx',
    component: () => import('../views/CampaignHyysbxNew.vue')
  },
  '/invoicecancel': {
    path: '/invoicecancel',
    name: 'invoicecancel',
    component: () => import('../views/InvoiceCancel.vue')
  },
  '/bflxlist': {
    path: '/bflxlist',
    name: 'bflxlist',
    component: () => import('../views/bflx/BflxList.vue')
  },
  '/bflxnew': {
    path: '/bflxnew',
    name: 'bflxnew',
    component: () => import('../views/bflx/BflxNew.vue')
  },
  '/bflxcard': {
    path: '/bflxcard',
    name: 'bflxcard',
    component: () => import('../views/bflx/BflxCard.vue')
  },
  '/bflxedit': {
    path: '/bflxedit',
    name: 'bflxedit',
    component: () => import('../views/bflx/BflxEdit.vue')
  },
  '/bflxnavigate': {
    path: '/bflxnavigate',
    name: 'bflxnavigate',
    component: () => import('../views/bflx/BflxNavigate.vue')
  },
  '/jhgllist': {
    path: '/jhgllist',
    name: 'jhgllist',
    component: () => import('../views/jhgl/JhglList')
  },
  '/plannew': {
    path: '/plannew',
    name: 'plannew',
    component: () => import('../views/jhgl/PlanNew.vue')
  },
  '/plamedit': {
    path: '/plamedit',
    name: 'plamedit',
    component: () => import('../views/jhgl/PlanEdit.vue')
  },
  '/plancard': {
    path: '/plancard',
    name: 'plancard',
    component: () => import('../views/jhgl/PlanCard.vue')
  },
  '/planscenario': {
    path: '/planscenario',
    name: 'planscenario',
    component: () => import('../views/jhgl/PlanScenario.vue')
  },
  '/accountlist': {
    path: '/accountlist',
    name: 'accountlist',
    component: () => import('../views/jhgl/AccountList')
  },
  '/rankinglist': {
    path: '/rankinglist',
    name: 'rankinglist',
    component: () => import('../components/homepage/CommonTitle/Rankinglist.vue')
  }
}
const routesTemp = {
  'chenxin/': {
    '/list': {
      path: '/list',
      name: 'chenxin/list',
      component: () => import('../views/project/chenxin/List.vue')
    },
    '/card': {
      path: '/card',
      name: 'chenxin/card',
      component: () => import('../views/project/chenxin/Card.vue')
    }
  },
  'yongchen/': {
    '/list': {
      path: '/list',
      name: 'yongchen/list',
      component: () => import('../views/project/yongchen/List.vue')
    }
  },
  'xinsheng/': {
    '/list': {
      path: '/list',
      name: 'xinsheng/list',
      component: () => import('../views/project/xinsheng/List.vue')
    }
  },
  'nuokang/': {
    '/list': {
      path: '/list',
      name: 'nuokang/list',
      component: () => import('../views/project/nuokang/List.vue')
    }
  },
  'krc/': {
    '/list': {
      path: '/list',
      name: 'krc/list',
      component: () => import('../views/project/krc/List.vue')
    },
    '/lxgzdscannew': {
      path: '/lxgzdscannew',
      name: 'krc/lxgzdscannew',
      component: () => import('../views/project/krc/Lxgzdscannew.vue')
    }
  },
  'hrty/': {
    '/list': {
      path: '/list',
      name: 'hrty/list',
      component: () => import('../views/project/hrty/List.vue')
    }
  },
  'whjm/': {
    // '/new': {
    //   path: '/new',
    //   name: 'whjm/new',
    //   component: () => import('../views/project/whjm/New.vue')
    // },
    // '/edit': {
    //   path: '/edit',
    //   name: 'whjm/edit',
    //   component: () => import('../views/project/whjm/Edit.vue')
    // },
    '/list': {
      path: '/list',
      name: 'whjm/list',
      component: () => import('../views/project/whjm/List.vue')
    },
    // '/new': {
    //   path: '/new',
    //   name: 'whjm/new',
    //   component: () => import('../views/New.vue')
    // },
    '/edit': {
      path: '/edit',
      name: 'whjm/edit',
      component: () => import('../views/Edit.vue')
    },
    // '/list': {
    //   path: '/list',
    //   name: 'whjm/list',
    //   component: () => import('../views/List.vue')
    // },
    //   '/ref': {
    //     path: '/ref',
    //     name: 'whjm/ref',
    //     component: () => import('../views/project/whjm/components/Ref.vue')
    //   },
    //   '/refmulti': {
    //     path: '/refmulti',
    //     name: 'whjm/refmulti',
    //     component: () => import('../views/project/whjm/components/Refmulti.vue')
    //   }
    // },
    // 'ba/': {
    //   'flowcard': {
    //     path: 'flowcard',
    //     name: 'ba/flowcard',
    //     component: () => import('../views/project/ba/flow/Flowcard.vue')
    //   }
    '/ref': {
      path: '/ref',
      name: 'whjm/ref',
      component: () => import('../components/Ref.vue')
    },
    '/refmulti': {
      path: '/refmulti',
      name: 'whjm/refmulti',
      component: () => import('../components/Refmulti.vue')
    }
  },
  'ba/': {
    'flowcard': {
      path: 'flowcard',
      name: 'ba/flowcard',
      component: () => import('../views/project/ba/flow/Flowcard.vue')
    }
  },
  'dinuo/': {
    '/list': {
      path: '/list',
      name: 'dinuo/list',
      component: () => import('../views/project/dinuo/List.vue')
    },
    '/card': {
      path: '/card',
      name: 'dinuo/card',
      component: () => import('../views/project/dinuo/Card.vue')
    },
    '/edit': {
      path: '/edit',
      name: 'dinuo/edit',
      component: () => import('../views/project/dinuo/Edit.vue')
    },
    '/ref': {
      path: '/ref',
      name: 'dinuo/ref',
      component: () => import('../views/project/dinuo/components/Ref.vue')
    },
    '/new': {
      path: '/new',
      name: 'dinuo/new',
      component: () => import('../views/project/dinuo/New.vue')
    },
    '/main': {
      path: '/main',
      name: 'dinuo/main',
      component: () => import('../views/project/dinuo/Main.vue')
    }

  }
}

const jsonData = require('../project.json')
let project = jsonData.project

if (project && project !== 'default/') {
  let projectRotes = routesTemp[project]

  for (let roteName in projectRotes) {
    defaultToutes[roteName] = projectRotes[roteName]
  }
}

const routes = []
for (let routeName in defaultToutes) {
  routes.push(defaultToutes[routeName])
}

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router
